/**
 * 创建目录
 */

const fs = require('fs')
const path = require('path')

function createFoldersAndFiles(target, name, skeletonData, atlasData) {
  if (!fs.existsSync(target) || !fs.lstatSync(target).isDirectory()) {
    fs.mkdirSync(target)
  }

  const folderPath = path.join(target, name)
  fs.mkdirSync(folderPath)
  try {
    fs.writeFileSync(path.join(folderPath, `${name}.json`), skeletonData)
  } catch (e) {

  }
  try {

    fs.writeFileSync(path.join(folderPath, `${name}.atlas`), atlasData.replace(/\\n/g, '\n'))
  } catch (e) {

  }
}

module.exports = createFoldersAndFiles
